class Solution {
public:
    int minLength(string s) {
        vector<int>ans;
        for (auto x : s) {
            ans.push_back(x);
            int len = ans.size();
            if (len >= 2) {
                bool f = 0;
                if (ans[len - 2] == 'A' && ans[len - 1] == 'B')f = 1;
                else if (ans[len - 2] == 'C' && ans[len - 1] == 'D')f = 1;

                if (f) {
                    ans.pop_back();
                    ans.pop_back();
                }
            }
        }
        return ans.size();
    }
};s